#ifndef MAINCONTROL_H
#define MAINCONTROL_H

#include <QObject>
#include <QDirIterator>

#include "head.h"
#include "savebase.h"
#include "savegroundlongwv.h"
#include "saveh264.h"
#include "saveairwv.h"

#include "configfileclass.h"
#include "myudpreceive.h"
#include "savemsg.h"

class MainControl : public QObject
{
    Q_OBJECT
public:
    explicit MainControl(QObject *parent = nullptr);
    ~MainControl();

public:
    void initThread();  //初始化所有线程

    void startThread(); //开始所有线程

    void stopThread();  //退出所有线程

    void startOneThread(int index);  //开始特定某条线程保存

    void stopOneThread(int index);   //停止特定某条线程保存

    QStringList getAllFileSavePath(); //获取总存储文件夹目录

private:
    QVector<QThread*> m_threads;

    QVector<MyUdpReceive*> m_udps;   //存储所有udp对象

    QVector<VIDEO_SAVE_CONFIG> m_videoConfigs;

    QVector<SaveBase*> m_saveThreads; //存储所有work对象

    QStringList m_allFileSavePath;      //总存储文件夹目录

    ConfigFileClass m_config;

    SaveMsg *m_saveMsg;     //短消息存储
public slots:
    void onStartStoring(CameraMethod method);   //开始某路存储
    void onStopStoring(CameraMethod method);     //停止某路存储
    void onQueryStatus();  //查询状态
    void onQueryVideo();    //查询视频
    void onDeleteVideo(QString path);   //删除视频
    void onTiming(QDateTime dataTime);   //授时
    void onChangeH264Time(quint8 time); //更改h264文件保存时长

signals:
    void signal_saveFileWork(const QString ip, const quint16 port, const QByteArray arr);
    void sigStartStoringResp(CameraMethod); //CameraMethod 开始存储
    void sigStopStoringResp(CameraMethod);  //CameraMethod停止存储
    void sigQueryStatusResp(bool midWaveIR, bool longWaveIR, bool visible, bool aerial);   //查询状态指令
    void sigQueryVideoResp(const QStringList &videoNames);           //查询视频
    void sigDeleteVideoResp(QString);   //删除视频
    void sigTimingResp();      //授时
    void sigAllDiskFull();  //通知上位机磁盘满了

    //测试，显示视频
    void sigToShowImg(const QString ip, const quint16 port, const QByteArray arr);
};

#endif // MAINCONTROL_H
